package logic

import (
	"context"
	"errors"
	"vip_srv/model/mysql"

	"vip_srv/internal/svc"
	"vip_srv/vip"

	"github.com/zeromicro/go-zero/core/logx"
)

type FindOneInfoByViperLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewFindOneInfoByViperLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FindOneInfoByViperLogic {
	return &FindOneInfoByViperLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *FindOneInfoByViperLogic) FindOneInfoByViper(in *vip.FindOneInfoByViperRequest) (*vip.FindOneInfoByViperResponse, error) {
	// todo: add your logic here and delete this line

	user := mysql.VipUser{}
	err := user.FindOneInfoByViper(int(in.Id))
	if err != nil {
		return nil, errors.New("账号或密码不正确")
	}

	return &vip.FindOneInfoByViperResponse{
		Title:   user.Title,
		Price:   user.Price,
		Cover:   user.Cover,
		Status:  user.Status,
		ShopNum: user.ShopNum,
	}, nil
}
